home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / ACROYNMity / main.c < prev    next >
C/C++ Source or Header  |  2000-06-23  |  4KB  |  120 lines

  1. // Acronymity
  2. // © 2000 by Karl Kornel (kornel.1@osu.edu)
  3. // Made during MacHack 2000
  4. // Changes & Redistribution allowed is credit given
  5.  
  6. /* Our headers */
  7. #include <iostream.h> // Basic input/output streams
  8. #include <iomanip.h> // Stream formatting
  9. #include <stdlib.h> // Standard functions
  10. #include <fstream.h> // For file stuff
  11. #include <unistd.h> // For sleep()
  12. #include <string.h> // For string stuff
  13.  
  14. /* Our special include */
  15. #include "settings.h" // Our user-definable settings
  16.  
  17. /* The prototypes for our support functions */
  18. bool confirmQuit(const char *acronym);
  19. bool confirmAdd(const char *acronym);
  20. void printHelp(void);
  21. void clearChar(char *,const int);
  22. void cleanAcronym(char *);
  23. bool isLetter(const char);
  24. char makeItLower(const char);
  25.  
  26. /* The prototypes for our file-interaction functions */
  27. void openFiles(void);
  28. int getWord(char *, const char);
  29. void closeFiles(void);
  30.  
  31. /* Our functions */
  32. int main(void) {
  33.     openFiles();
  34.  
  35.     const int finalPhraseLength = (acronymLength * wordLength) - acronymLength; // Obvious
  36.     char acronym[acronymLength + 1]; // The acronym
  37.     char word[wordLength + 1]; // Holders for each word
  38.     char finalPhrase[finalPhraseLength]; // The final phrase
  39.     
  40.     int realAcronymLength = acronymLength; // The length of the actual acronym (minus the \0)
  41.     int realWordLength; // The length of the actual word (minus the \0)
  42.     int realPhraseLength = 0; // The length of the actual phrase (minus the \0)
  43.     
  44.     /* Initialize the strings */
  45.     clearChar(acronym,acronymLength);
  46.     clearChar(word,wordLength);
  47.     clearChar(finalPhrase,finalPhraseLength);
  48.     
  49.     /* Display credits & intro, get acronym */
  50.     cout << "ACROYNMity  -  By Karl Kornel\n"
  51.         << "Free use for all MacHackers\n"
  52.         << "©2000 Karl Kornel for anyone else\n\n"
  53.         << "Made in the USA for MacHack 2000\n" 
  54.         << "Thanks to Mike Ferris for the words.\n"
  55.         << "Thanks to Eric Tolmach for the support\n\n""" << endl;
  56.     
  57.     cout << "Enter an acronym for me to expand.  Enter quit to quit.\n"
  58.         << "Enter add for information on adding words.\n"
  59.         << "The acronym can be up to " << acronymLength <<" characters long\n\n"
  60.         << "Acronym...: ";
  61.     
  62.     cin >> acronym;
  63.     
  64.     /* Transfer the call for 'add' or 'quit' */
  65.     if (confirmQuit(acronym))
  66.         exit(0);
  67.     else if (confirmAdd(acronym)) {
  68.         printHelp();
  69.         exit(0);
  70.     }
  71.     
  72.     /* Clean the acronym */
  73.     cout << "Stand by, cleaning up acronym..." << endl;
  74.     cout << " Acronym " << acronym << " has been converted to ";
  75.     cleanAcronym(acronym); // Clean it up
  76.     cout << acronym << '.' << endl;
  77.     
  78.     sleep(3);
  79.     
  80.     /* Get ready to reveal the magic phrase */
  81.     cout << "\n\n\n\n\n" << endl << "Expanding acronym " << acronym << "..." << endl;
  82.     
  83.     cout << "Acronym " << acronym << " expands to the letters/words:\n";
  84.     
  85.     /* Find out how long the phrase is */
  86.     for (int temp = 0;temp <= acronymLength;temp++)
  87.         if (acronym[temp] == '\0') {
  88.             realAcronymLength = temp;
  89.             break;
  90.         }
  91.     
  92.     /* Now, start displaying and constructing the components */
  93.     for (int temp = 1;temp <= realAcronymLength;temp++) {
  94.         /* Output the letter */
  95.         cout << ' ' << acronym[temp - 1] << ": "; // The letter & some space
  96.         
  97.         /* Get the word & find out how long it is */
  98.         realWordLength = getWord(word,acronym[temp - 1]); // Get the word & it's real length
  99.         for (int temp2 = 1;temp2 <= realWordLength;temp2++) // For each character in the word
  100.             cout << word[temp2 - 1]; // Output the character
  101.         cout << endl; // Output a newline
  102.         
  103.         /* Add the word to the phrase */
  104.         strcat(word," "); // Add a space
  105.         strcat(finalPhrase,word);
  106.     }
  107.     cout << "The phrase: " << finalPhrase << endl;
  108.     
  109.     /* Finally, output everything again */
  110.     for (int i=0;i <= 50 - 1;i++)
  111.         cout << '\n';
  112.     cout << endl;
  113.     
  114.     cout << "Before, you had\n\n" << acronym << endl;
  115.     
  116.     cout << "\n\n\nNow, you have\n\n" << finalPhrase;
  117.     
  118.     /* Lastly, close everything down */
  119.     closeFiles();
  120. }